package com.shr.lease.web.app.service.impl;

import com.shr.lease.model.entity.ApartmentInfo;
import com.shr.lease.model.entity.FacilityInfo;
import com.shr.lease.model.entity.LabelInfo;
import com.shr.lease.model.enums.ItemType;
import com.shr.lease.web.app.mapper.*;
import com.shr.lease.web.app.service.ApartmentInfoService;
import com.shr.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.shr.lease.web.app.vo.apartment.ApartmentItemVo;
import com.shr.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Resource
    private ApartmentInfoMapper apartmentInfoMapper;
    @Resource
    private FacilityInfoMapper facilityInfoMapper;
    @Resource
    private LabelInfoMapper labelInfoMapper;
    @Resource
    private GraphInfoMapper graphInfoMapper;
    @Resource
    private RoomInfoMapper roomInfoMapper;


    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        //1、基本信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectApartmentInfoById(id);
        //2、图片列表
        List<GraphVo> graphVos = graphInfoMapper.listGraphVo(id, ItemType.APARTMENT);
        //3、标签列表
        List<LabelInfo> labelInfos = labelInfoMapper.listLableInfoByApartmentId(id);
        //4、配套列表
        List<FacilityInfo> facilityInfos = facilityInfoMapper.listFacilityInfoByApartmentId(id);
        //5、最少租金
        BigDecimal minRent = roomInfoMapper.getMinRent(id);

        ApartmentDetailVo apartmentDetailVo = ApartmentDetailVo.builder()
                .graphVoList(graphVos)
                .facilityInfoList(facilityInfos)
                .labelInfoList(labelInfos)
                .minRent(minRent)
                .build();
        BeanUtils.copyProperties(apartmentInfo,apartmentDetailVo);
        return apartmentDetailVo;
    }
}




